home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PsL Monthly 1993 December
/
PSL Monthly Shareware CD-ROM (December 1993).iso
/
prgmming
/
dos
/
c
/
tsr_c.exe
/
VECTORS.C
< prev
next >
Wrap
C/C++ Source or Header
|
1992-03-24
|
4KB
|
168 lines
#include <stdio.h>
#include <stdlib.h>
#include <dos.h>
#include "vectors.h"
void interrupt (*old_8) (void);
void interrupt (*old_23) (void);
void interrupt (*old_24) (void);
void interrupt (*old_28) (void);
void interrupt (*old_2F) (void);
BYTE _8_chk_dos = 1; // check for DOS busy in the 8 handler?
WORD _8_count = 0;
WORD _8_flag = 0;
WORD _8_max = 18;
WORD _8_stack[STACKSIZE] = {0};
WORD _8_ss;
WORD _8_sp;
WORD want_in = 0;
WORD _28_flag = 0;
WORD far *indos;
WORD old_psp;
void enter_tsr (int x)
{
if (_8_chk_dos)
{
_AH = 0x62; // get current PSP
geninterrupt (0x21);
old_psp = _BX; // save it
_AH = 0x50; // UNDOC DOS Set PSP to ours
_BX = _psp;
geninterrupt (0x21);
old_23 = getvect (0x23); // CTRL-Break handler
setvect (0x23, new_23);
old_24 = getvect (0x24); // critical error handler
setvect (0x24, new_24);
}
tsr (x);
if (_8_chk_dos)
{
setvect (0x24, old_24); // reset them
setvect (0x23, old_23);
_AH = 0x50;
_BX = old_psp;
geninterrupt (0x21); // set the old psp back
}
}
void interrupt new_8 ()
{
old_8 (); // call old vector
if (++_8_count >= _8_max)
{
want_in = 1;
_8_count = 0;
if (!_8_flag)
{
if (DOSOK () || (!_8_chk_dos))
{
want_in = 0;
_8_flag = 1;
BEGINSTACK (_8_); // switch to our stack
enter_tsr (8);
ENDSTACK (_8_); // switch from our stack
_8_flag = 0;
}
}
}
}
void interrupt new_28 (void)
{
if (want_in == 1)
{
if (!_8_flag)
{
if (DOS28OK () || (!_8_chk_dos))
{
want_in = 0;
_8_flag = 1;
BEGINSTACK (_8_); // switch to our stack
enter_tsr (0x28);
ENDSTACK (_8_); // switch from our stack
_8_flag = 0;
}
}
}
else
chain (old_28);
}
#pragma argsused
void interrupt new_2F (bp,di,si,ds,es,dx,cx,bx,ax,ip,cs,flags)
{
if (_AH == MY_ID) // for me
{
// if successful, AX = -1, BX = our PSP, and DX = our data segment
switch (_AL)
{
case DETECT_CMD:
ax = 0xFFFF;
bx = _psp;
dx = _DS;
break;
case UNLOAD_CMD:
// if vect's can be unloaded then they are, else
// the first offending vect is returned in CX
if (FP_SEG(getvect (0x28)) == FP_SEG(new_28))
{
if (FP_SEG(getvect (0x08)) == FP_SEG(new_8))
{
if (FP_SEG(getvect (0x2F)) == FP_SEG(new_2F))
{
ax = 0xFFFF;
bx = _psp;
dx = _DS;
setvect (0x08, old_8);
setvect (0x2F, old_2F);
setvect (0x28, old_28);
}
else
cx = 0x2F;
}
else
cx = 8;
}
else
cx = 0x28;
break;
default:
chain (old_2F);
}
return;
}
else
if (_AX == 0x7A85) // novell broadcast msg
{
}
chain (old_2F);
}
void interrupt new_23 (void)
{
// do nothing
}
#pragma argsused
void interrupt new_24 (bp,di,si,ds,es,dx,cx,bx,ax,ip,cs,flags)
{
ax = 3; // fail the function
}